﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
//.............
using QLKTX1._0.DTO;
using QLKTX1._0.DB;
using System.Data.SqlClient;
using System.Data;
//...................

namespace QLKTX1._0.DAO
{
    class ChucVuDAO
    {
        public static List<ChucVuDTO> dsChucVu()
        {
            List<ChucVuDTO> dsChucVu = new List<ChucVuDTO>();          

            ConnectDB con = new ConnectDB();
            DataTable dt = con.getDataTable("SELECT * FROM ChucVu order by (tenChucVu) asc");

            for (int i = 0; i < dt.Rows.Count; i++)
            {     
                               
                ChucVuDTO cv = new ChucVuDTO();
                cv.MaChucVu = Int32.Parse(dt.Rows[i]["maChucVu"].ToString());
                cv.TenChucVu = dt.Rows[i]["tenChucVu"].ToString();
                dsChucVu.Add(cv);

            }

            return dsChucVu;
        }
        //ham them 
        public static bool themChucVu(ChucVuDTO cv)
        {
            ConnectDB con = new ConnectDB();
            return con.executeQuery("INSERT INTO ChucVu(tenChucVu) VALUES(N'" + cv.TenChucVu + "')");
        }
        //ham xoa 
        public static bool xoaChucVu(ChucVuDTO cv)
        {
            ConnectDB con = new ConnectDB();
            return con.executeQuery("DELETE FROM ChucVu WHERE maChucVu=" + cv.MaChucVu + " ");
        }
        //ham cap nhat 
        public static bool capNhatChucVu(ChucVuDTO cv)
        {
            ConnectDB con = new ConnectDB();
            return con.executeQuery("UPDATE ChucVu set tenChucVu=N'" + cv.TenChucVu + "' WHERE maChucVu=" + cv.MaChucVu + " ");
        }
    }
}
